package com.kupurui.asteacher.ui.job;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.UnCorrectInfo;
import com.kupurui.asteacher.ui.BaseFgt;
import com.kupurui.asteacher.utils.URLImageParser;

import butterknife.Bind;
import butterknife.OnClick;
import info.hoang8f.widget.FButton;

/**
 * Created by Administrator on 2017/8/9.
 */

public class TopicDetailsFgt extends BaseFgt {

    @Bind(R.id.tv_next)
    TextView tvNext;
    @Bind(R.id.tv_subject)
    TextView tvSubject;
    @Bind(R.id.tv_num)
    TextView tvNum;
    @Bind(R.id.tv_total)
    TextView tvTotal;
    @Bind(R.id.fbtn_correct)
    FButton fbtnCorrect;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_answer)
    TextView tvAnswer;
    @Bind(R.id.tv_analysis)
    TextView tvAnalysis;
    @Bind(R.id.tv_serial_number)
    TextView tvSerialNumber;

    private int position = 0;
    private int size = 0;
    private String list_size = "";
    TopicDetailsAty aty;

    UnCorrectInfo unCorrectInfo;


    @Override
    public int getLayoutId() {
        return R.layout.topic_details_fgt;
    }

    @Override
    public void initData() {
        aty = (TopicDetailsAty) getActivity();
        if (getArguments() != null) {
            position = getArguments().getInt("fgt_position");
            size = getArguments().getInt("size");
            list_size = getArguments().getString("list_size");
            unCorrectInfo = (UnCorrectInfo) getArguments().getSerializable("bean");
        }
        if (1 == size) {
            tvNext.setVisibility(View.GONE);
        } else {
            tvNext.setVisibility(View.VISIBLE);
        }
        tvSerialNumber.setText("("+unCorrectInfo.getSerial_number()+")");
        tvNum.setText((position + 1) + "");
        tvTotal.setText("/" + list_size);

        tvTitle.setText(Html.fromHtml(unCorrectInfo.getTitle(), new URLImageParser(getActivity(),tvTitle), null));
        tvAnswer.setText(Html.fromHtml(unCorrectInfo.getTrue_answer(), new URLImageParser(getActivity(),tvAnswer), null));
        tvAnalysis.setText(Html.fromHtml(unCorrectInfo.getJiexi(), new URLImageParser(getActivity(),tvAnalysis), null));


    }

    @Override
    public void requestData() {

    }

    @OnClick({R.id.tv_next, R.id.fbtn_correct})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.tv_next://下一题
                aty.changeView(position + 1);
                break;
            case R.id.fbtn_correct://开始批改
                Bundle bundle = new Bundle();
                bundle.putString("qusition", unCorrectInfo.getId());
                bundle.putString("work_id", getActivity().getIntent().getStringExtra("id"));
                bundle.putString("class_id", getActivity().getIntent().getStringExtra("class_id"));
                startActivity(CorrectAty.class, bundle);
                break;
        }
    }

}
